#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

void solve()
{
    int n; cin >> n;
    vector<int>s(n + 1);
    for(int i = 1;i <= n;i ++) cin >> s[i];
    map<int,int>m;
    auto checkval = [&]()
    {
        return m[2] >= 2 && m[0] >= 3 && m[1] >= 1 && m[5] >= 1 && m[3] >= 1;
    };
    for(int i = 1;i <= n;i ++)
    {
        m[s[i]]++;
        if(checkval())
        {
            cout << i << endl;
            return;
        }
    }
    cout << 0 << endl;
}
int main()
{
    int tx; cin >> tx;
    while(tx--)
    {
        solve();
    }
    return 0;
}